package com.mdlib.helper.ui.fragments.home;


import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.util.Log;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.ljlib.core.base.BaseFragment;
import com.ljlib.help.R;
import com.mdlib.helper.ui.adapter.GenericViewPagerAdapter;
import com.mdlib.helper.ui.fragments.rush.my.RushHistoryOrderFragment;
import com.mdlib.helper.ui.fragments.rush.my.RushOngoingOrderFragment;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;

/**
 * 作者：HQY on 16/11/28 14:22
 * 邮箱：hqy_xz@126.com
 */

public class RushMyOrdersFragment extends BaseFragment {


    @Bind(R.id.rl_generic_back)
    RelativeLayout mRlGenericBack;
    @Bind(R.id.tv_generic_title)
    TextView mTvGenericTitle;
    @Bind(R.id.tab_rush_mey_order_top)
    TabLayout mTabRushMeyOrderTop;
    @Bind(R.id.vp_rush_my_order_pager)
    ViewPager mVpRushMyOrderPager;


    private RushHistoryOrderFragment rushHistoryOrderFragment;
    private RushOngoingOrderFragment rushOngoingOrderFragment;

    private FragmentPagerAdapter myOrderAdapter;

    private List<Fragment> listFragment;
    private boolean resumeNum;
    private List<String> titlFragment;

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_rush_my_orders;
    }

    @Override
    protected void initView(View rootView) {
        super.initView(rootView);

        init();

    }

    private void init() {
        mTvGenericTitle.setText(getActivity().getResources().getString(R.string.my_order_title));
        rushOngoingOrderFragment = new RushOngoingOrderFragment();
        rushHistoryOrderFragment = new RushHistoryOrderFragment();


        listFragment = new ArrayList<>();
        listFragment.add(rushOngoingOrderFragment);
        listFragment.add(rushHistoryOrderFragment);

        titlFragment = new ArrayList<>();
        titlFragment.add(getActivity().getResources().getString(R.string.my_order_ongoing) );
        titlFragment.add(getActivity().getResources().getString(R.string.my_order_history));

        mTabRushMeyOrderTop.setTabMode(TabLayout.MODE_FIXED);

        mTabRushMeyOrderTop.addTab(mTabRushMeyOrderTop.newTab().setText(titlFragment.get(0)));
        mTabRushMeyOrderTop.addTab(mTabRushMeyOrderTop.newTab().setText(titlFragment.get(1)));

        myOrderAdapter = new GenericViewPagerAdapter(getActivity().getSupportFragmentManager(), listFragment, titlFragment);
        mVpRushMyOrderPager.setAdapter(myOrderAdapter);
        mTabRushMeyOrderTop.setupWithViewPager(mVpRushMyOrderPager);


    }

    @Override
    public void onResume() {
        super.onResume();
        boolean flag = getActivity().getIntent().getBooleanExtra("history", false);
        if (flag && !resumeNum) {
            mVpRushMyOrderPager.setCurrentItem(1);
            resumeNum = true;
        }
    }
}
